package com.lz.football.module.techBar.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	import com.lz.football.module.base.IComponent;
	
	import common.item.GoodsItem;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import lz.controls.LItem;
	import lz.controls.events.ListEvent;

	/**
	 *科技馆物品item  
	 * @author lake
	 * 
	 */	
	public class TechGoodsItem extends GoodsItem
	{
		public function TechGoodsItem()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			if(value != null && value == _data)
			{
				return;
			}
			_data = value;
			var goodsVo :GoodsVo 		= value;
			DisplayObjectUtil.removeAllChildren(container);
			if(goodsVo)
			{
				if(goodsVo.type == GoodsType.PLAYERCARD)
				{
					container.addChild(colorBg);
					colorBg.y = -0.5;
					colorBg.x = -0.7;
					colorBg.gotoAndStop(goodsVo.color);
				}
				else
				{
					if(colorBg && colorBg.parent)
					{
						colorBg.parent.removeChild(colorBg);
					}
				}
				var bitmapData :BitmapData 	= goodsVo.bitmapData;
				var bitmap :Bitmap = new Bitmap(bitmapData);
				bitmap.scaleX = 1;
				bitmap.scaleY = 1;
				bitmap.x = -1;
				container.addChild(bitmap);
			}
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		override public function initUI(view:Object=null):void
		{
			_symbolSkin = view as MovieClip;
			container = new MovieClip();
			_symbolSkin.addChild(container);
			colorBg = Reflection.createInstance("com.lz.res.PlayerColorBg");
			addEvtListener();
		}
		/**
		 * 添加事件
		 * 
		 */		
		override public function addEvtListener():void
		{
			_symbolSkin.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			_symbolSkin.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			_symbolSkin.addEventListener(MouseEvent.CLICK,onClickHandler);
			_symbolSkin.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 * 单击
		 * @param e
		 * 
		 */		
		override protected function onClickHandler(e:MouseEvent):void
		{
			this.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK,true,false,-1,-1,-1,_data));
		}
		/**
		 * 删除事件
		 * 
		 */		
		override public function removeEvtListener():void
		{
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			_symbolSkin.removeEventListener(MouseEvent.CLICK,onClickHandler);
			_symbolSkin.removeEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
	}
}